----------------------------------------------------------------------------------
-- Company: 
-- Engineer: 
-- 
-- Create Date:    13:25:17 04/16/2012 
-- Design Name: 
-- Module Name:    video_logic_unit - Behavioral 
-- Project Name: 
-- Target Devices: 
-- Tool versions: 
-- Description: 
--
-- Dependencies: 
--
-- Revision: 
-- Revision 0.01 - File Created
-- Additional Comments: 
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;

-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity video_logic_unit is
    Port (
			clk : in std_logic;
			red : out std_logic_vector (2 downto 0);
			green : out std_logic_vector (2 downto 0);
			blue : out std_logic_vector (1 downto 0);
			h_sync : out std_logic;
			v_sync : out std_logic;
			top_collision : in std_logic;
			bottom_collision : in std_logic;
			h_count : out std_logic_vector(10 downto 0);
			v_count : out std_logic_vector(10 downto 0);
			player1_here, player2_here, ball_here, brick_here : in std_logic
		);
end video_logic_unit;

architecture Behavioral of video_logic_unit is

	component vga_controller_800_60 is
		port(
			rst         : in std_logic;
			pixel_clk   : in std_logic;

			HS          : out std_logic;
			VS          : out std_logic;
			hcount      : out std_logic_vector(10 downto 0);
			vcount      : out std_logic_vector(10 downto 0);
			blank       : out std_logic
		);
	end component;

	signal should_blank : std_logic;

begin

	timing_controller : vga_controller_800_60
	port map (
		rst => '0',
		pixel_clk => clk,
		HS => h_sync,
		VS => v_sync,
		blank => should_blank,
		hcount => h_count,
		vcount => v_count
	);

	process(clk, should_blank, player1_here, player2_here, ball_here)
	begin
		
		if should_blank = '1' then
			red <= (others => '0');
			green <= (others => '0');
			blue <= (others => '0');
		elsif player1_here = '1' then
			red <= (others => '1');
			green <= (others => '1');
			blue <= (others => '1');
		elsif player2_here = '1' then
			red <= (others => '1');
			green <= (others => '0');
			blue <= (others => '0');
		elsif ball_here = '1' then
			red <= (others => '0');
			green <= (others => '1');
			blue <= (others => '0');
		elsif brick_here = '1' then
			red <= (others => '0');
			green <= (others => '0');
			blue <= (others => '0');
		elsif top_collision = '1' then
			red <= (others => '1');
			green <= (others => '0');
			blue <= (others => '0');
		elsif bottom_collision = '1' then
			red <= (others => '1');
			green <= (others => '1');
			blue <= (others => '1');
		else
			red <= (others => '0');
			green <= (others => '0');
			blue <= (others => '1');
		end if;
	end process;


end Behavioral;

